#!/usr/bin/env node
const process = require('process');
const { exec } = require('child_process');
const path = require('path');

const currDir = process.cwd();

const buildFileName = 'dist';
const currBuildDir = path.resolve(currDir, buildFileName);
const pemFilePath = path.resolve(currDir, '../devops-nginx.pem');

exec(
  `scp -i ${pemFilePath} -r ${currBuildDir}/** ubuntu@101.35.209.150:/home/ubuntu/pms/web`,
  (error, output, stderr) => {
    if (error || stderr) {
      console.log('\x1b[31m', '发布失败', error);
      process.exit(1);
    } else {
      console.log('\x1b[32m', '发布成功', output);
      process.exit(0);
    }
  },
);
